home *** CD-ROM | disk | FTP | other *** search
- /*******************************************
- *
- * edge_region(..
- *
- * This function segments an image by
- * growing regions inside of edges.
- * The steps are:
- * . detect edges
- * . threshold edge output to a
- * percent value
- * . remove edges from consideration
- * . grow regions
- *
- *******************************************/
-
- edge_region(in_name, out_name, the_image, out_image,
- il, ie, ll, le, edge_type, min_area,
- max_area, diff, percent, set_value,
- erode)
- char in_name[], out_name[];
- float percent;
- int edge_type, il, ie, ll, le;
- short diff, erode,
- max_area, min_area,
- set_value,
- the_image[ROWS][COLS],
- out_image[ROWS][COLS];
- {
-
- int a, b, count, i, j, k,
- length, width;
- short cutoff;
- struct tiff_header_struct image_header;
- unsigned long histogram[GRAY_LEVELS+1];
-
- if(does_not_exist(out_name)){
- printf("\n\n output file does not exist %s",
- out_name);
- read_tiff_header(in_name, &image_header);
- round_off_image_size(&image_header,
- &length, &width);
- image_header.image_length = length*ROWS;
- image_header.image_width = width*COLS;
- create_allocate_tiff_file(out_name, &image_header,
- out_image);
- } /* ends if does_not_exist */
- read_tiff_image(in_name, the_image, il, ie, ll, le);
-
- /***************************
- *
- * Detect the edges. Do
- * not threshold.
- *
- ****************************/
-
- if(edge_type == 1 ||
- edge_type == 2 ||
- edge_type == 3)
- detect_edges(in_name, out_name, the_image,
- out_image, il, ie, ll, le,
- edge_type, 0, 0);
-
- if(edge_type == 4){
- quick_edge(in_name, out_name, the_image,
- out_image, il, ie, ll, le,
- 0, 0);
- } /* ends if 4 */
-
- if(edge_type == 5){
- homogeneity(in_name, out_name, the_image,
- out_image, il, ie, ll, le,
- 0, 0);
- } /* ends if 5 */
-
- if(edge_type == 6){
- difference_edge(in_name, out_name, the_image,
- out_image, il, ie, ll, le,
- 0, 0);
- } /* ends if 6 */
-
- if(edge_type == 7){
- contrast_edge(in_name, out_name, the_image,
- out_image, il, ie, ll, le,
- 0, 0);
- } /* ends if 7 */
-
- if(edge_type == 8){
- gaussian_edge(in_name, out_name, the_image,
- out_image, il, ie, ll, le,
- 3, 0, 0);
- } /* ends if 8 */
-
- if(edge_type == 10){
- range(in_name, out_name, the_image,
- out_image, il, ie, ll, le,
- 3, 0, 0);
- } /* ends if 10 */
-
- if(edge_type == 11){
- variance(in_name, out_name, the_image,
- out_image, il, ie, ll, le,
- 0, 0);
- } /* ends if 11 */
-
- /* copy out_image to the_image */
- for(i=0; i<ROWS; i++)
- for(j=0; j<COLS; j++)
- the_image[i][j] = out_image[i][j];
-
- /******************************
- *
- * Threshold the edge detector
- * output at a given percent.
- * This eliminates the weak
- * edges.
- *
- *******************************/
-
- zero_histogram(histogram);
- calculate_histogram(the_image, histogram);
- find_cutoff_point(histogram, percent, &cutoff);
- threshold_image_array(the_image, out_image,
- 255, cutoff, set_value);
-
- if(erode != 0){
- /* copy out_image to the_image */
- for(i=0; i<ROWS; i++)
- for(j=0; j<COLS; j++)
- the_image[i][j] = out_image[i][j];
- erode_image_array(the_image, out_image,
- set_value, erode);
- } /* ends if erode */
-
-
- /*******************************
- *
- * Set all the edge values to
- * FORGET_IT so the region
- * growing will not use those
- * points.
- *
- *******************************/
-
- for(i=0; i<ROWS; i++)
- for(j=0; j<COLS; j++)
- if(out_image[i][j] == set_value)
- out_image[i][j] = FORGET_IT;
-
- for(i=0; i<ROWS; i++)
- for(j=0; j<COLS; j++)
- the_image[i][j] = out_image[i][j];
-
- pixel_grow(the_image, out_image, diff,
- min_area, max_area);
-
- write_array_into_tiff_image(out_name, out_image,
- il, ie, ll, le);
-
- } /* ends edge_region */
-
-